package cn.bocweb.spinning.presenter.Imp;

import android.text.TextUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

import cn.bocweb.spinning.model.Imp.UserModelImp;
import cn.bocweb.spinning.model.Model;
import cn.bocweb.spinning.presenter.UserPresenter;
import cn.bocweb.spinning.util.DeviceUtil;
import de.greenrobot.event.EventBus;

/**
 * Created by chenchangxing on 16/1/7.
 */
public class UserPresenterImp implements UserPresenter {

    Model model;
    String timeline;

    public UserPresenterImp() {
        model = new UserModelImp();
        DeviceUtil.Log("timeMillis =" + System.currentTimeMillis());
        timeline = String.valueOf(System.currentTimeMillis()).substring(0, 10);
    }

    @Override
    public void regVerify(String phone) {
        model.regVerify(timeline, DeviceUtil.getSign(timeline), phone);
    }

    @Override
    public void sign(String userid) {
        model.sign(timeline, DeviceUtil.getSign(timeline), userid);
    }

    @Override
    public void login(String phone, String pwd) {
        pwd = DeviceUtil.getBase64(pwd);
        model.login(timeline, DeviceUtil.getSign(timeline), phone, pwd);
    }

    @Override
    public void getjixing(String userid, String banbenhao, String jixing) {

        model.getjixing(timeline, DeviceUtil.getSign(timeline), userid, banbenhao, jixing);
    }

    @Override
    public void changePwd(String userid, String pwd, String newpwd, String confirmpwd) {
        pwd = DeviceUtil.getBase64(pwd);
        newpwd = DeviceUtil.getBase64(newpwd);
        confirmpwd = DeviceUtil.getBase64(confirmpwd);

        model.changePwd(timeline, DeviceUtil.getSign(timeline), userid, pwd, newpwd, confirmpwd);
    }

    @Override
    public void reg(String nickname, String pwd, String confirmpwd, String phone, String verify) {
        pwd = DeviceUtil.getBase64(pwd);
        confirmpwd = DeviceUtil.getBase64(confirmpwd);

        model.reg(timeline, DeviceUtil.getSign(timeline), nickname, phone, verify, pwd, confirmpwd);
    }

    @Override
    public void findVerify(String phone) {
        model.findVerify(timeline, DeviceUtil.getSign(timeline), phone);
    }

    @Override
    public void findPwd(String phone, String pwd, String confirmpwd, String verify) {
        pwd = DeviceUtil.getBase64(pwd);
        confirmpwd = DeviceUtil.getBase64(confirmpwd);
        model.findPwd(timeline, DeviceUtil.getSign(timeline), phone, pwd, confirmpwd, verify);
    }

    @Override
    public void updateInfo(String userid, String nickname, String realname, String company, String position, String tel, String gender, String address, String code, File file, String filename) {
        try {
            model.updateInfo(timeline, DeviceUtil.getSign(timeline), userid, nickname, realname, company, position, tel, gender, address, code, file, filename, "1");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void getCtype() {
        model.getCtype(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void getFlag(String ctype) {
        model.getFlag(timeline, DeviceUtil.getSign(timeline), ctype);
    }

    @Override
    public void getIhome(String ctype, String page, String page_size) {
        model.getIhome(timeline, DeviceUtil.getSign(timeline), ctype, page, page_size, "");
    }

    @Override
    public void getIhomeMain() {
        model.getIhome(timeline, DeviceUtil.getSign(timeline), "", "1", "3", "");
    }

    @Override
    public void getIhomeSearch(String ctype, int page, String search) {
        model.getIhome(timeline, DeviceUtil.getSign(timeline), ctype, String.valueOf(page), "9", search);
    }

    @Override
    public void getAdd(String id, String userid) {
        model.getAdd(timeline, DeviceUtil.getSign(timeline), id, userid);
    }

    @Override
    public void libList() {
        model.libList(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void getCommentTotal(String id) {
        model.getCommentTotal(timeline, DeviceUtil.getSign(timeline), id);
    }

    @Override
    public void getCommentDetail(String id, String page, String page_size) {
        model.getCommentDetail(timeline, DeviceUtil.getSign(timeline), id, page, page_size);
    }

    @Override
    public void insertComment(String id, String userid, String content) {
        model.insertComment(timeline, DeviceUtil.getSign(timeline), id, userid, content);
    }

    @Override
    public void getMyComments(String userid, String page, String page_size) {
        model.getMyComment(timeline, DeviceUtil.getSign(timeline), userid, page, page_size);
    }

    @Override
    public void addFavorites(String aid, String userid) {
        model.addFavorites(timeline, DeviceUtil.getSign(timeline), aid, userid);
    }

    @Override
    public void startExam(String userid, String libtype) {
        model.startExam(timeline, DeviceUtil.getSign(timeline), userid, libtype);
    }


    @Override
    public void finishExam(String testid, String userid, String spend_time, String detail, String libtype) {
        model.finishExam(timeline, DeviceUtil.getSign(timeline), testid, userid, spend_time, detail, libtype);
    }

    @Override
    public void testRecord(String userid, String libtype, String pagecount, String page) {
        model.testRecord(timeline, DeviceUtil.getSign(timeline), userid, libtype, pagecount, page);
    }

    @Override
    public void testDetail(String userid, String testid) {
        model.testDetail(timeline, DeviceUtil.getSign(timeline), userid, testid);
    }

    @Override
    public void testKeys(String userid, String testid) {
        model.testKeys(timeline, DeviceUtil.getSign(timeline), userid, testid);
    }

    @Override
    public void testError(String userid, String testid) {
        model.testErrors(timeline, DeviceUtil.getSign(timeline), userid, testid);
    }

    @Override
    public void trainRandomStart(String count, String libtype, String userid, String init) {
        model.trainRandomStart(timeline, DeviceUtil.getSign(timeline), count, libtype, userid, init);
    }

    @Override
    public void trainRandom(String count, String libtype, String userid, String init) {
        model.trainRandom(timeline, DeviceUtil.getSign(timeline), count, libtype, userid, init);
    }

    @Override
    public void trainRandomKeys(String count, String id, String ttype, String libtype, String isright, String choose, String userid) {
        model.trainRandomKeys(timeline, DeviceUtil.getSign(timeline), count, id, ttype, libtype, isright, choose, userid);
    }

    @Override
    public void getCollectFavorites(String userid, int page, String page_size) {
        model.getCollectFavorites(timeline, DeviceUtil.getSign(timeline), userid, String.valueOf(page), page_size);
    }

    @Override
    public void forumMyCollect(int page, String pagecount, String userid) {
        model.forumMyCollect(timeline, DeviceUtil.getSign(timeline), String.valueOf(page), pagecount, userid);
    }

    @Override
    public void errorTrainStart(String count, String libtype, String userid) {
        model.errorTrainStart(timeline, DeviceUtil.getSign(timeline), count, libtype, userid);
    }

    @Override
    public void errorTrain(String count, String libtype, String userid) {
        model.errorTrain(timeline, DeviceUtil.getSign(timeline), count, libtype, userid);
    }

    @Override
    public void errorKeys(String count, String id, String ttype, String libtype, String isright, String choose, String userid) {
        model.errorKeys(timeline, DeviceUtil.getSign(timeline), count, id, ttype, libtype, isright, choose, userid);
    }

    @Override
    public void testCollect(String id, String ttype, String libtype, String userid, String isright, String choose) {
        model.testCollect(timeline, DeviceUtil.getSign(timeline), id, ttype, libtype, userid, isright, choose);
    }

    @Override
    public void hardTrainStart(String count, String libtype, String userid) {
        model.hardTrainStart(timeline, DeviceUtil.getSign(timeline), count, libtype, userid);
    }

    @Override
    public void hardTrain(String count, String libtype, String userid) {
        model.hardTrain(timeline, DeviceUtil.getSign(timeline), count, libtype, userid);
    }

    @Override
    public void hardKeys(String count, String id, String ttype, String libtype, String isright, String userid) {
        model.hardKeys(timeline, DeviceUtil.getSign(timeline), count, id, ttype, libtype, isright, userid);
    }

    @Override
    public void collectList(String libtype, String userid, String pagecount, int page) {
        model.collectList(timeline, DeviceUtil.getSign(timeline), libtype, userid, pagecount, String.valueOf(page));
    }

    @Override
    public void collectQuestion(int count, String userid, String libtype) {
        DeviceUtil.Log("collectQuestion = " + count);
        model.collectQuestion(timeline, DeviceUtil.getSign(timeline), String.valueOf(count + 1), userid, libtype);
    }

    @Override
    public void collectRemove(String libtype, String userid, String type, String count, String ttype) {
        model.collectRemove(timeline, DeviceUtil.getSign(timeline), libtype, userid, type, count, ttype);
    }

    @Override
    public void sequenceTest(int count, String libtype, String userid) {
        model.sequenceTest(timeline, DeviceUtil.getSign(timeline), String.valueOf(count + 1), libtype, userid);
    }

    @Override
    public void sequenceKeys(int count, String id, String ttype, String libtype, String isright, String choose, String userid) {
        model.sequenceKeys(timeline, DeviceUtil.getSign(timeline), String.valueOf(count+1), id, ttype, libtype, isright, choose, userid);
    }

    @Override
    public void sequenceList(String libtype, String userid, String pagecount, int page) {
        model.sequenceList(timeline, DeviceUtil.getSign(timeline), libtype, userid, pagecount, String.valueOf(page));
    }

    @Override
    public void getMsg(String userid, String type, String pagecount, String page) {
        model.getMsg(timeline, DeviceUtil.getSign(timeline), userid, type, pagecount, page);
    }

    @Override
    public void feedBack(String userid, String question) {
        model.feedBack(timeline, DeviceUtil.getSign(timeline), userid, question);
    }

    @Override
    public void myClass(String userid, String libtype) {
        model.myClass(timeline, DeviceUtil.getSign(timeline), userid, libtype);
    }

    @Override
    public void delExamrecord(String libtype, String userid, String type, String id) {
        model.delExamrecord(timeline, DeviceUtil.getSign(timeline), libtype, userid, type, id);
    }

    @Override
    public void testRank(String libtype, String userid, String interval, String pagecount, String page) {
        model.testRank(timeline, DeviceUtil.getSign(timeline), libtype, userid, interval, pagecount, page);
    }

    @Override
    public void CollectKey(String count, String userid, String libtype, String choose, String isright) {
        model.collectKey(timeline, DeviceUtil.getSign(timeline), count, userid, libtype, choose, isright);
    }

    @Override
    public void myFeedback(String userid) {
        model.myFeedback(timeline, DeviceUtil.getSign(timeline), userid);
    }

    @Override
    public void newFeedback(String userid) {
        model.newFeedback(timeline, DeviceUtil.getSign(timeline), userid);
    }

    @Override
    public void helpList(String pagecount, String page) {
        model.helpList(timeline, DeviceUtil.getSign(timeline), pagecount, page);
    }

    @Override
    public void helpAddress(String id) {
        model.helpAddress(timeline, DeviceUtil.getSign(timeline), id);
    }

    @Override
    public void delFavorites(String aid, String userid) {
        model.delFavorites(timeline, DeviceUtil.getSign(timeline), aid, userid);
    }

    @Override
    public void delComment(String id, String userid) {
        model.delComment(timeline, DeviceUtil.getSign(timeline), id, userid);
    }

    @Override
    public void sequenceSync(String libtype, String userid, String data) {
        model.sequenceSync(timeline, DeviceUtil.getSign(timeline), libtype, userid, data);
    }

    @Override
    public void indexSlider() {
        model.indexSlider(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void registerDoc() {
        model.registerDoc(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void getCompanyList1(String page, String userid) {
        model.getCompanyList1(timeline, DeviceUtil.getSign(timeline), "9", page, userid);
    }

    @Override
    public void getCompanyIntro(String id) {
        model.getCompanyIntro(timeline, DeviceUtil.getSign(timeline), id);
    }

    @Override
    public void getCompanyCerify(String id) {
        model.getCompanyCerify(timeline, DeviceUtil.getSign(timeline), id);
    }

    @Override
    public void getCompanyContact(String id) {
        model.getCompanyContact(timeline, DeviceUtil.getSign(timeline), id);
    }

    @Override
    public void getCompanyCollect(String id, String userid, String type) {
        model.getCompanyCollect(timeline, DeviceUtil.getSign(timeline), id, userid, type);
    }

    @Override
    public void getCollectCompany(String userid, String page) {
        model.getCollectCompany(timeline, DeviceUtil.getSign(timeline), userid, "9", page);
    }

    @Override
    public void getCompanySearchCat() {
        model.getCompanySearchCat(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void getCompanySearchLocation() {
        model.getCompanySearchLocation(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void getProductList(String page, String userid) {
        model.getProductList(timeline, DeviceUtil.getSign(timeline), "9", page, userid);
    }

    @Override
    public void collectProduct(String id, String userid, String type) {
        model.collectProduct(timeline, DeviceUtil.getSign(timeline), id, userid, type);
    }

    @Override
    public void getProductDetail(String id) {
        model.getProductDetail(timeline, DeviceUtil.getSign(timeline), id);
    }

    @Override
    public void getProductCollectList(String userid, int page) {
        model.getProductCollectList(timeline, DeviceUtil.getSign(timeline), userid, "9", String.valueOf(page));
    }

    @Override
    public void getProductSearchCat() {
        model.getProductSearchCat(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void forunGetCate() {
        model.forunGetForun(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void sendForun(String userid, String cat, String title, String content, List<File> files) {
        if (cat != null && !cat.isEmpty()) {
            model.sendForun(timeline, DeviceUtil.getSign(timeline), userid, cat, title, content, files);
        } else {
            DeviceUtil.Log("empty");
        }
    }

    @Override
    public void getForum1List(int page, int type) {
        model.getForum1List(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), String.valueOf(type));
    }

    @Override
    public void getForum2List(int page, int type) {
        model.getForum2List(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), String.valueOf(type));
    }

    @Override
    public void getForumListForMain(int page, int type) {
        model.getForum1List(timeline, DeviceUtil.getSign(timeline), "3", String.valueOf(page), String.valueOf(type));
    }

    @Override
    public void getReplyList(int page, String userid) {
        model.getReplyList(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), userid);
    }

    @Override
    public void getCompanyList2(String city, String cat, String keyword, String userid, int page) {
        String json = "{\"city\":\"" + city + "\",\"cat\":\"" + cat + "\",\"keyword\":\"" + keyword + "\"}";
        DeviceUtil.Log(json);
        model.getCompanyList2(timeline, DeviceUtil.getSign(timeline), json, userid,  String.valueOf(page), "9");
    }

    @Override
    public void getProductList2(String city, String cat, String keyword, String userid, int page) {
        String json = "{\"city\":\"" + city + "\",\"cat\":\"" + cat + "\",\"keyword\":\"" + keyword + "\"}";
        DeviceUtil.Log(json);
        model.getProductList2(timeline, DeviceUtil.getSign(timeline), json, userid, String.valueOf(page), "9");
    }

    @Override
    public void getFirstMatch() {
        model.getFirstMatch(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void getFirstReward(String userid) {
        model.getFirstReward(timeline, DeviceUtil.getSign(timeline), userid);
    }

    @Override
    public void testRule() {
        model.testRule(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void testExamRule() {
        model.testExamRule(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void secondTest(String userid, String libtype, String lasttime) {
        model.secondTest(timeline, DeviceUtil.getSign(timeline), userid, libtype, lasttime);
    }

    @Override
    public void secondRule() {
        model.secondRule(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void qaappGetCat() {
        model.qaappGetCat(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void qaList(int page, String cat) {
        model.qaList(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), cat);
    }

    @Override
    public void qaList2(int page, String cat) {
        model.qaList2(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), cat);
    }

    @Override
    public void qaListMain() {
        model.qaList(timeline, DeviceUtil.getSign(timeline), "3", "1", "all");
    }

    @Override
    public void qaMyList(int page, String userid) {
        model.qaMyList(timeline, DeviceUtil.getSign(timeline), "10", String.valueOf(page), userid);
    }

    @Override
    public void qaDetail(String id, int page) {
        model.qaDetail(timeline, DeviceUtil.getSign(timeline), id, "9", String.valueOf(page));
    }

    @Override
    public void qaCheck(String id, String userid, String answer) {
        model.qaCheck(timeline, DeviceUtil.getSign(timeline), id, userid, answer);
    }

    @Override
    public void qaMyAnswer(int page, String userid) {
        model.qaMyAnswer(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), userid);
    }

    @Override
    public void qaPublish(String userid, String cat, String score, String content, List<File> files) {
        model.qaPublish(timeline, DeviceUtil.getSign(timeline), userid, cat, score, content, files);
    }

    @Override
    public void qaUserScore(String userid) {
        model.qaUserScore(timeline, DeviceUtil.getSign(timeline), userid);
    }

    @Override
    public void qaAnswer(String userid, String id, String content) {
        model.qaAnser(timeline, DeviceUtil.getSign(timeline), userid, id, content);
    }

    @Override
    public void matchInvite() {
        model.matchInvite(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void matchShare(String userid, String testid) {
        model.matchShare(timeline, DeviceUtil.getSign(timeline), userid, testid);
    }

    @Override
    public void qaDelMyQuestion(String userid, String id) {
        model.qaDelMyQuestion(timeline, DeviceUtil.getSign(timeline), userid, id);
    }

    @Override
    public void qaDelMyAnswer(String userid, String id) {
        model.qaDelMyAnswer(timeline, DeviceUtil.getSign(timeline), userid, id);
    }

    @Override
    public void getMyForum(int page, String userid) {
        model.getMyForum(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), userid);
    }

    @Override
    public void delMyForum(String userid, String id) {
        model.delMyForum(timeline, DeviceUtil.getSign(timeline), userid, id);
    }

    @Override
    public void forumDetail(String userid, String id, int page) {
        model.forumDetail(timeline, DeviceUtil.getSign(timeline), userid, id, String.valueOf(page));
    }

    @Override
    public void forumUp(String userid, String id, boolean liked) {
        model.forumUp(timeline, DeviceUtil.getSign(timeline), userid, id, liked ? "2" : "1");
    }

    @Override
    public void forumCollect(String userid, String id, boolean collected) {
        model.forumCollect(timeline, DeviceUtil.getSign(timeline), userid, id, collected ? "2" : "1");
    }

    @Override
    public void forumComment(String userid, String forumId, String content, String location, List<File> files) {
        model.forumComment(timeline, DeviceUtil.getSign(timeline), userid, forumId, content, location, files);
    }

    @Override
    public void reportType() {
        model.reportType(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void report(String userid, String id, String report) {
        model.report(timeline, DeviceUtil.getSign(timeline), userid, id, report);
    }

    @Override
    public void society(int page, String userid) {
        model.society(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), userid);
    }

    @Override
    public void societyDetail(int page, String userid, String id) {
        model.societyDetail(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), userid, id);
    }

    @Override
    public void commentReply(String connect_id, String userid, String content, List<File> files) {
        model.commentReply(timeline, DeviceUtil.getSign(timeline), connect_id, userid, content, files);
    }

    @Override
    public void forumDel(String userid, String type, String id) {
        model.forumDel(timeline, DeviceUtil.getSign(timeline), userid, type, id);
    }

    @Override
    public void oldFangList(int page) {
        model.oldFang(timeline, DeviceUtil.getSign(timeline), String.valueOf(page), "9");
    }

    @Override
    public void oldFangBanner() {
        model.oldFangBanner(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void oldFangDetail(String id, String userid) {
        model.oldFangDetail(timeline, DeviceUtil.getSign(timeline), id, userid);
    }

    @Override
    public void oldFangTotal(String id) {
        model.oldFangTotal(timeline, DeviceUtil.getSign(timeline), id);
    }

    @Override
    public void oldFangComments(String id, int page) {
        model.oldFangComments(timeline, DeviceUtil.getSign(timeline), id, String.valueOf(page), "9");
    }

    @Override
    public void oldFangInsertComment(String id, String userid, String content) {
        model.oldFangInsertComment(timeline, DeviceUtil.getSign(timeline), id, userid, content);
    }

    @Override
    public void oldFangFavorite(String aid, String userid) {
        model.oldFangFavorite(timeline, DeviceUtil.getSign(timeline), aid, userid);
    }

    @Override
    public void getShopList(int page, String userid) {
        model.getShopList(timeline, DeviceUtil.getSign(timeline), "9", String.valueOf(page), userid);
    }

    @Override
    public void getScoreList(int page, String userid) {
        model.getScoreList(timeline, DeviceUtil.getSign(timeline), userid, String.valueOf(page));
    }

    @Override
    public void getExchargeList(int page, String userid) {
        model.getExChargeList(timeline, DeviceUtil.getSign(timeline), userid, String.valueOf(page));
    }

    @Override
    public void getExcharge(String userid, String id, String name, String tel, String address) {
        if (TextUtils.isEmpty(name)) {
            EventBus.getDefault().post("请输入姓名");
            return;
        }
        if (TextUtils.isEmpty(tel)) {
            EventBus.getDefault().post("请输入联系电话");
            return;
        }
        if (TextUtils.isEmpty(address)) {
            EventBus.getDefault().post("请输入收件地址");
            return;
        }
        if (!tel.substring(0, 1).equals("1") || tel.length() != 11) {
            EventBus.getDefault().post("请输入正确的手机号");
            return;
        }
        model.getExcharge(timeline, DeviceUtil.getSign(timeline), userid, id, name, tel, address);
    }

    @Override
    public void getVersion() {
        model.getVersion(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void getVid(String userid, String vid) {
        model.getVid(timeline, DeviceUtil.getSign(timeline), userid, vid);
    }

    @Override
    public void secondTime() {
        model.secondTime(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void downloadfirst(String jsonStr) {
        model.downloadfirst(timeline, DeviceUtil.getSign(timeline), jsonStr);
    }

    @Override
    public void secondDownload() {
        model.secondDownload(timeline, DeviceUtil.getSign(timeline));
    }

    @Override
    public void secondHandle1(String userid, String start, String libtype, String score, String testid) {
        model.secondHandle1(timeline, DeviceUtil.getSign(timeline), userid, start, libtype, score, testid);
    }

    @Override
    public void signStatus(String userid) {
        model.signStatus(timeline, DeviceUtil.getSign(timeline), userid);
    }

    @Override
    public void secondEnter(String userid, String libtype) {
        model.secondEnter(timeline, DeviceUtil.getSign(timeline), userid, libtype);
    }

    @Override
    public void myClassNew(String userid) {
        model.myClassNew(timeline, DeviceUtil.getSign(timeline), userid);
    }


    @Override
    public void secondTimeJudge() {
        model.secondTimeJudge(timeline, DeviceUtil.getSign(timeline));
    }
}
